/**
 * 迭代器实现类
 * @author shuang
 * @date 2022/10/20 9:56
 */
public class ConcreteIterator implements Iterator {
    
    private int current = 0;

    /**
     * 迭代的对象
     */
    private ConcreteAggregate aggregate;
    
    /**
     * 初始化时，将聚集器对象传入
     * @param aggregate
     */
    public ConcreteIterator(ConcreteAggregate aggregate) {
        this.aggregate = aggregate;    
    }
    
    @Override
    public Object first() {
        return aggregate.get(0);
    }
    
    /**
     * 获取下一个对象
     * @return
     */
    @Override
    public Object next() {
        Object res = null;
        if (current < aggregate.count()) {
            res = aggregate.get(current);
        }
        current ++;
        return res;
    }
    
    /**
     * 是否迭代结束
     * @return
     */
    @Override
    public Boolean isDone() {
        return current >= aggregate.count();
    }
    
    @Override
    public Object currentItem() {
        return aggregate.get(current);
    }
}